package com.softcomputer.rpt.ejb;

import com.softcomputer.rpt.entity.User;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@Stateless
public class LoginSession implements Serializable {

    @PersistenceContext(unitName = "Exchanger")
    private EntityManager em;
    private static final Log LOG = LogFactory.getLog(ExchangeSession.class);

    public List<User> retrieve() {

        Query getAllUsersQuery = em.createNamedQuery("User.findAll");
        try {
            return getAllUsersQuery.getResultList();
        } catch (Exception exception) {
            LOG.error("Unable to retrieve log messages from entity manager: " + exception.getMessage());
            return new ArrayList<User>();
        }

    }
}
